package com.sljy.hzk.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sljy.hzk.R;
import com.sljy.hzk.entity.ExamMainEntity;
import com.sljy.hzk.util.TimeUtils;
import com.sljy.hzk.view.FocusEffct;

import java.util.ArrayList;
import java.util.List;

import static com.sljy.hzk.util.TimeUtils.compare_date;

public class ExamNoticeAdapter  extends BaseAdapter {

    private List<ExamMainEntity.ExamListBean> Datas0;
    private List<ExamMainEntity.ExamListBean> Datas1;
    private List<ExamMainEntity.ExamListBean> Datas2;
    private Context mContext;
    private int defaultState = 0;

    public ExamNoticeAdapter(List<ExamMainEntity.ExamListBean> datas, Context mContext) {
        //日期分类
        Datas0 = new ArrayList<ExamMainEntity.ExamListBean>();
        Datas1 = new ArrayList<ExamMainEntity.ExamListBean>();
        Datas2 = new ArrayList<ExamMainEntity.ExamListBean>();
        String n =  TimeUtils.dateToStr(TimeUtils.getNowDate());
        for(ExamMainEntity.ExamListBean data : datas){
            switch (TimeUtils.compare_date(n,data.getDate())){
                case 0:
                    Datas0.add(data);
                    break;
                case 1:
                    Datas1.add(data);
                    break;
                case -1:
                    Datas2.add(data);
                    break;
            }
        }
        this.mContext = mContext;
    }
    @Override
    public int getCount() {
        return getState().size();
    }

    @Override
    public Object getItem(int position) {
        return getState().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder=new ViewHolder();
            //可以理解为从vlist获取view 之后把view返回给ListView
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_exam_notice,parent,false);
            holder.posNameStr = (TextView)convertView.findViewById(R.id.posText);
            holder.contentStr = (TextView) convertView.findViewById(R.id.contentText);
            holder.timeStr = (TextView) convertView.findViewById(R.id.timeText);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        ExamMainEntity.ExamListBean d = getState().get(position);
        holder.posNameStr.setText(d.getExamName());
        holder.contentStr.setText(d.getPartition());
        //String str = d.getDate();
       // str = str.substring(str.length()-5, str.length());
        //holder.timeStr.setText(str.replace("-",":"));
        holder.timeStr.setText(  d.getStartTime().replace("-null",""));
        return convertView;
    }

    public void refresh(int state){
        defaultState = state;
        notifyDataSetChanged();
    }

    private List<ExamMainEntity.ExamListBean> getState(){
        switch (defaultState){
            case 1:
                return Datas1;
            case 2:
                return Datas2;
        }
        return Datas0;
    }

    public final class ViewHolder {
        public TextView posNameStr;
        public TextView contentStr;
        public TextView timeStr;
    }
}
